package pers.lls.hds.stack;

/**
 * @author lilichai
 */
public class StackX {


    private int maxSize;
    private Object[] stackArray;
    private int top;

    public StackX(int max) {
        maxSize = max;
        stackArray = new Object[maxSize];
        top = -1;
    }

    public void push(Object j) {
        stackArray[++top] = j;
    }

    public Object pop() {
        return stackArray[top--];
    }

    public Object peek() {
        return stackArray[top];
    }

    public boolean isEmpty() {
        return (top == -1);
    }

    public static void main(String[] args) {
        StackX stackX = new StackX(5);
        stackX.push(1);
        stackX.push(2);
        stackX.push(3);
        stackX.push(4);
        System.out.println(stackX.peek());
        for (int i = 0; i < 4; i++){
            System.out.println(stackX.pop());
        }
    }

}



